﻿using Pfz.RemoteGaming.Internal;
using Pfz.Threading;

namespace Pfz.RemoteGaming
{
	/// <summary>
	/// This class is responsible for holding an UnsafeThreadedAnimation.
	/// When disposed or collected it will release the thread used by such
	/// animation.
	/// </summary>
	public sealed class ThreadedAnimation:
		ThreadedIterator
	{
		/// <summary>
		/// Creates a new ThreadedAnimation from the given action.
		/// </summary>
		/// <param name="action"></param>
		/// <returns></returns>
		public new static ThreadedAnimation CreateFromAction(IteratorAction action)
		{
			return new _UnsafeThreadedAnimationFromAction(action);
		}

		private ThreadedAnimation(UnsafeThreadedAnimation unsafeAnimation):
			base(unsafeAnimation)
		{
		}

		/// <summary>
		/// Implicit cast from UnsafeThreadedAnimation to ThreadedAnimation.
		/// </summary>
		public static implicit operator ThreadedAnimation(UnsafeThreadedAnimation unsafeAnimation)
		{
			return new ThreadedAnimation(unsafeAnimation);
		}
	}
}
